package com.xinqi.modules.exam.paper.controller.admin;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.exam.paper.dto.req.CourseExamPaperCreateDTO;
import com.xinqi.modules.exam.paper.dto.req.CourseExamPaperQueryDTO;
import com.xinqi.modules.exam.paper.dto.req.CourseExamPaperUpdateDTO;
import com.xinqi.modules.exam.paper.dto.rsp.CourseExamPaperResultDTO;
import com.xinqi.modules.exam.paper.service.CourseExamPaperService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 课程测评Admin控制层
 *
 * @author: linkai
 * @date: 2023/07/02
 */
@Tag(name = "Admin-课程测评", description = "课程测评Admin接口")
//@RestController
@RequestMapping("/admin/exam-paper")
@RequiredArgsConstructor
public class CourseExamPaperAdminController {
    private final CourseExamPaperService courseExamPaperService;

    /**
     * 课程测评-分页
     */
    @Operation(summary = "课程测评-分页")
    @GetMapping("/page")
    public R<PageInfo<CourseExamPaperResultDTO>> page(@ParameterObject CourseExamPaperQueryDTO dto) {
        PageInfo<CourseExamPaperResultDTO> page = courseExamPaperService.page(dto, dto);
        return R.data(page);
    }

    /**
     * 课程测评-详情
     */
    @Operation(summary = "课程测评-详情")
    @GetMapping("/{id}")
    public R<CourseExamPaperResultDTO> findById(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        CourseExamPaperResultDTO dto = courseExamPaperService.findById(id);
        return R.data(dto);
    }

    /**
     * 新增课程测评
     */
    @Operation(summary = "新增课程测评")
    @PostMapping
    public R<Long> insert(@RequestBody CourseExamPaperCreateDTO dto) {
        return R.data(courseExamPaperService.insert(dto));
    }

    /**
     * 修改课程测评
     */
    @Operation(summary = "修改课程测评")
    @PutMapping("/{id}")
    public R<Boolean> update(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id,
                             @RequestBody CourseExamPaperUpdateDTO dto) {
        dto.setId(id);
        return R.data(courseExamPaperService.updateById(dto));
    }

    /**
     * 删除课程测评
     */
    @Operation(summary = "删除课程测评")
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@Parameter(description = "id", example = "100001") @PathVariable("id") Long id) {
        return R.data(courseExamPaperService.deleteById(id));
    }
}
